import { KitchensolutionService } from './../service/kitchensolutionService';
import { Response, ServiceConfig, route, Guid } from '../common';
import { Device } from '../domain/model';
import { WebException } from './webException';
import assert = require("assert");
import * as Koa from "koa";

export class KitchensolutionController {
    private kitchensolutionService: KitchensolutionService;
    constructor() {
        this.kitchensolutionService = ServiceConfig.Current.GetService<KitchensolutionService>("kitchensolutionService");
    }

    toString(){
        return "KitchensolutionController";
    }


    //获取所有的订单   
    @route({ method: 'get', path: '/api/kitchensolutions' })
    private async getKitchensolutions(ctx: Koa.Context, next) {
        const query = ctx.request.query;
        const paramsWhite = ["id", "media"];
        for (let key in query) {
            if (paramsWhite.indexOf(key) == -1) {
                throw new WebException( key + "参数不合法");
            }
        }
        if (query.id) {
            query.ids = [query.id];
        }
        if (query.id instanceof Array) {
            query.ids = query.id;
            delete query.id;
        }
        const kitchensolutions = await this.kitchensolutionService.queryKitchensolutions(query)
        ctx.response.body = Response.ok("Kitchensolutions查询成功", kitchensolutions);;
        await next();
    }
}